package community.ui.question;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import community.domain.Question;
import community.exception.DatabaseException;
import community.service.IQuestionService;
import community.service.impl.QuestionService;

/**
 * Servlet implementation class QuestionServlet
 */
@WebServlet("/Question/ShowQuestion")
public class ShowQuestionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	IQuestionService questionService = new QuestionService();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowQuestionServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ArrayList<Question> questions;
		try {
			questions = questionService.getQuestion(0);
			request.setAttribute("questions", questions);
			request.getRequestDispatcher("showquestion.jsp").forward(request, response);
			return;
		} catch (DatabaseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

}
